<%@page pageEncoding = "utf-8" contentType = "text/html;charset=utf-8"%>

<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions"%>

<h2>Справочник клиентов</h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<p>
  <a href = "adminui?_action=clientForm"><fmt:message key = "Command.add"/></a>
</p>

<p>
  <a href="adminui?_action=clientsList&type=all">
    <fmt:message key="Command.all"/>
  </a>

  <a href="adminui?_action=clientsList&type=active">
    <fmt:message key="Command.active"/>
  </a>

  <a href="adminui?_action=clientsList&type=inactive">
    <fmt:message key="Command.inactive"/>
  </a>
</p>


   <table width="100%" cellpadding="10" cellspacing="10">
      <thead>
         <tr style="border-bottom: 1px #f1f1f1 solid;">            
           <th><a class="head" href="adminui?_action=clientsList&orderBy=name&order=${order}&type=${type}&page=${currentPage}"><fmt:message key = "client.lastName"/></a></th>                        
           <th><a class="head" href="adminui?_action=clientsList&orderBy=tel&order=${order}&type=${type}&page=${currentPage}"><fmt:message key = "client.tel1"/></a></th>
           <th><a class="head" href="adminui?_action=clientsList&orderBy=email&order=${order}&type=${type}&page=${currentPage}"><fmt:message key = "client.email1"/></a></th>
           <th><a class="head" href="adminui?_action=clientsList&orderBy=www&order=${order}&type=${type}&page=${currentPage}"><fmt:message key = "client.www"/></a></th>
           <th><fmt:message key = "client.operations"/></th>
         </tr>
      </thead>

      <tbody>

           <c:forEach var = "client" items = "${clientsList}">
            <tr style="border-bottom: 1px #f1f1f1 solid;">               
               <td><c:out value = "${client.formName}"/></td>               
               <td><c:out value = "${client.tel1}"/></td>
               <td><a href="mailto:${client.email1}">${client.email1}</a></td>
               <td><c:out value = "${client.www}"/></td>
               <td>
                  <c:choose>
                   <c:when test="${client.status == 'active'}">                     
                        <a href = "adminui?_action=deleteClient&orderBy=${orderBy}&order=${order}&type=${type}&page=${currentPage}&client_id=${client.id}"
                           onclick="return confirm('Вы действительно хотите удалить клиента?')"
                        >
                           <fmt:message key = "client.operations.remove"/>
                        </a>                        
                   </c:when>
                  <c:otherwise>
                        <a href = "adminui?_action=restoreClient&orderBy=${orderBy}&order=${order}&type=${type}&page=${currentPage}&client_id=${client.id}">
                           <fmt:message key = "client.operations.restore"/>
                        </a>
                    </c:otherwise>     
                  </c:choose>                     
                        <a href = "adminui?_action=clientForm&client_id=${client.id}">
                           <fmt:message key = "client.operations.edit"/>
                        </a>                   
               </td>
            </tr>
         </c:forEach>

        <c:if test="${fn:length(clientsList) == 0}">      
          <tr><td colspan = "5" align="center">Список пуст</td></tr>
        </c:if>
        
      </tbody>
   </table>

<p><jsp:include page = "/pageNavigation.jsp"/></p>

<p>
<a class = "control" href = "adminui?_action=clientForm">
  <fmt:message key = "Command.add"/>
</a>
</p>